// pages_user/commission_sum/commission_sum.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    tab:[{id:1,tabname:'全部'},{id:2,tabname:'今日'},{id:3,tabname:'本周'},{id:4,tabname:'本月'}],
    list:[],
    commissionTotal:0,
    currPage:1,
    perPage:8,
    loading:true,
    perTotal:0,//每一页的数据数目
    status:'',
    isvoer:true,
    theme:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // app.setTheme();
    this.setData({
      theme : app.theme
    })
    // this.commissionList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.perTotal < this.data.perPage)  {
      app.functions.showToast('没有更多了~')
      return;
    }
    this.data.currPage=parseInt(this.data.currPage)+1;
    this.commissionList();

  },
  onSearch(e){
    this.setData({
      value:e.detail,
      list:[],
      currPage:1
    },()=>{
      this.commissionList();
    })
  },
  onChange(event) {
    this.setData({
      active:event.detail.index
    })
    if(event.detail.index==0){
      this.data.status=null;
    }else if(event.detail.index==1){
      this.data.status=0;
    }else if(event.detail.index==2){
      this.data.status=1;
    }else if(event.detail.index==3){
      this.data.status=2;
    }
    this.setData({
      list:[],
      currPage:1,
      loading:true
    },()=>{
      this.commissionList();
    })
  },
  commissionList(){
    let that=this;
    if(that.data.loading!=true)return;
    let userInfo = app.functions.getLocalStorage('user');
    let params={
      shopId: userInfo.id,
      type: that.data.status,
      offset: (that.data.currPage - 1) * that.data.perPage,
      limit: that.data.perPage
    };
    // app.api.commissionSum(params,(response)=>{
    //   const {rows}=response.data.logs;
    //   if(rows.length==0){
    //     this.setData({
    //       loading:false
    //     })
    //   }
    //   if(that.data.currPage==1){
    //     that.setData({
    //       isvoer:true,
    //       perTotal:rows.length,
    //       commissionTotal:response.data.commissionTotal,
    //       list:rows
    //     })
    //   }else{
    //     that.setData({
    //       perTotal:rows.length,
    //       list:that.data.list.concat(rows)
    //     })
    //   }
    // },(error)=>{

    // })

  },

})